package cn.tedu.ivos.user.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.base.response.StatusCode;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos.user.pojo.dto.UserQuery;
import cn.tedu.ivos.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import cn.tedu.ivos.user.service.UserSevice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "用户模块")
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserSevice userSevice;

    @ApiOperation("用户登录")
    @PostMapping("login")
    public JsonResult login(UserLoginParam userLoginParam){
        UserVO userVO = userSevice.SelectByUserName(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @ApiOperation("保存用户")
    @PostMapping("save")
    public JsonResult saveUser(UserSaveParam userSaveParam){
        log.debug("保存用户:userSaveParam={}"+userSaveParam);
        userSevice.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation("查询用户")
    @GetMapping("select")
    public JsonResult selectUser(UserQuery userQuery){
        log.debug("查询用户:userQuery={}"+userQuery);
        List<UserVO> list = userSevice.selectUser(userQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("删除用户")
    @DeleteMapping ("{id}/delete")
    public JsonResult deleteUserById(@PathVariable Long id){
        userSevice.deleteUserById(id);
        return JsonResult.ok();
    }

    @ApiOperation("重置密码")
    @PostMapping("/update/password/{UserId}")
    public JsonResult resetPassword(@PathVariable Long UserId){
        log.debug("重置密码,userId="+UserId);
        userSevice.resetPassword(UserId);
        return JsonResult.ok();
    }

    @ApiOperation("修改用户状态")
    @PostMapping("/update/status/{userId}/{status}")
    public JsonResult updateStatus(@PathVariable Long userId,@PathVariable String status){
        log.debug("修改用户状态,userId={},status={}",userId,status);
        userSevice.updateStatus(userId,status);
        return JsonResult.ok();
    }

    @ApiOperation("查询上级审批人列表")
    @GetMapping("/select/audit/{parentId}")
    public JsonResult selectAuditList(@PathVariable Long parentId){
        log.debug("查询上级审批人列表:parentId={}",parentId);
        List<UserVO> list = userSevice.selectAuditList(parentId);
        return JsonResult.ok(list);
    }
}
